import os

def add_slash_to_path(path: str):
    '''
        Adds slash (/) at ending of line if necessary.
    '''

    if path[-1] != "/":
        path += "/"

    return path


def get_directories(entries: list, path: str) -> list:
    '''
        Returns list of directories in entries which located in path.
    '''
    
    path = add_slash_to_path(path)

    dirs = []
    for entry in entries:
        if os.path.isdir(path + entry):
            dirs.append(entry)

    return dirs


def get_files(entries: list, path: str) -> list:
    '''
        Returns list of files in entries which located in path.
    '''
    
    path = add_slash_to_path(path)

    files = []
    for entry in entries:
        if not os.path.isdir(path + entry):
            files.append(entry)

    return files


def directories_first(entries: list, path: str):
    '''
        Sorts so that directories stand first, and then files.
    '''

    path = add_slash_to_path(path)

    dirs = []
    files = []

    for entry in entries:
        if os.path.isdir(path + entry):
            dirs.append(entry)
        else:
            files.append(entry)

    return dirs + files

